package com.example.banksystem.controller;

import com.example.banksystem.dto.TransferRequest;
import com.example.banksystem.entity.Transaction;
import com.example.banksystem.service.TransferService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

@RestController
@RequestMapping("/transfers")
@CrossOrigin(origins = "*")
public class TransferController {
    private final TransferService transferService;

    public TransferController(TransferService transferService) {
        this.transferService = transferService;
    }

    // 处理转账请求
    @PostMapping
    public ResponseEntity<Transaction> doTransfer(@Valid @RequestBody TransferRequest request) {
        Transaction transaction = transferService.transfer(request);
        return ResponseEntity.ok(transaction);
    }
}